
import Debug.QuickCheck

-- a new type for representing vectors
data Vector = Vector Double Double

-- computes the length of a vector
vecLength :: Vector -> Double
vecLength (Vector x y) = sqrt (x*x + y*y)

-- adds two vectors
vecAdd :: Vector -> Vector -> Vector
vecAdd (Vector x1 y1) (Vector x2 y2) =
  Vector (x1+x2) (y1+y2)

-- triangle law: the straight way is shortest
prop_TriangleLaw x y x' y' =
  vecLength (vecAdd v v') <=
    vecLength v + vecLength v'
 where
  v  = Vector x y
  v' = Vector x' y'
